package com.bootdo.site.controller;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.bootdo.common.config.Constant;
import com.bootdo.common.controller.BaseController;
import com.bootdo.common.domain.FileDO;
import com.bootdo.common.domain.PageDO;
import com.bootdo.common.utils.FileType;
import com.bootdo.common.utils.FileUtil;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.site.domain.SiteDO;
import com.bootdo.site.service.SiteService;

@RequestMapping("site")
@Controller
public class SiteController extends BaseController{
	@Autowired
	SiteService siteService;
	
	
    //为了跳转list页面
	@GetMapping()
	String site() {
		return  "site/site";
		
	}
	@ResponseBody	
	@GetMapping("/list")
	PageDO<SiteDO> List(@RequestParam Map<String, Object> params){
		Query query = new Query(params);
		PageDO<SiteDO> page = siteService.queryList(query);
		return page;
	}
	
	@ResponseBody
	@PostMapping("/remove")
	R remove(Long id) {
		if (siteService.remove(id)>0) {
			return R.ok();
		}
		return R.error();
	}
   //批量删除
	@ResponseBody
	@PostMapping("/batchRemove")
	R batchRemove(@RequestParam("ids[]") Long[] ids) {
		int r = siteService.batchRemove(ids);
		if (r > 0) {
			return R.ok();
		}
		return R.error();
	}
	
	//为了跳转添加页面
	@GetMapping("/add")
	String add() {
		return "site/add";
	}			
	
	//为了跳转修改页面
	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Long id, Model model) {
		SiteDO site = siteService.get(id);
		model.addAttribute("site", site);
		return "site/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(SiteDO site) {
		if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
			return R.error(1, "演示系统不允许修改,完整体验请部署程序");
		}
		if (siteService.save(site) > 0) {
			return R.ok();
		}
		return R.error();
	}

	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update(SiteDO site) {
		if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
			return R.error(1, "演示系统不允许修改,完整体验请部署程序");
		}
		siteService.update(site);
		return R.ok();
	}
	
	
	
	
	
	

}
